new Vue({
  el: '#app',
  data() {
    return {
      form: {
        SQLSerialNumber: "P_business_store_inventory",
        PaginationNumber: 1,//页数
        RowAmount: 10,//每页数据条数
        Condition: '',
        ExtensionCondition: '',
      },
      total: 0,
      tableData: [],	//表格数据
      dialogVisible: false,
      Supplier_Article_Stock_SerialNumber: '',
      loading: false,
    }
  },
  mounted() {
    this.getList(this.form);//前端分页
  },
  methods: {
    onSerach() {			//查询方法
      this.form.PaginationNumber = 1;
      this.getList(this.form)
    },
    Add() {
      window.location.href = './add.html'
    },
    handleSizeChange(val) {
      this.form.PaginationNumber = 1;
      this.form.RowAmount = val;
      this.getList(this.form)
    },
    handleCurrentChange(val) {
      this.form.PaginationNumber = val;
      this.getList(this.form)
    },
    getList(form) {//换页方法
      const that = this
      let data = deepClone(form);
      // data.Condition = window.btoa(unescape(encodeURIComponent("%"+data.Supplier_Name+"%")))
      $.ajax({
        headers: requestHeaders(),
        url: `${BASE_URL2}/generalBusiness/generalPaginationQueryBySQLSerialNumber`,
        type: 'POST',
        data,
        success: function (Result) {
          that.tableData = Result.Rows;
          that.total = Result.TotalRows;
        },
        complete: function (XMLHttpRequest) {
          requestPretreatment(XMLHttpRequest);
        },
        dataType: "json"
      });
    },
    downloadTemplate(command) {
      if (command == "stock") {
        window.location.href = './download/导入供应库存模板.xlsx';
      }
    },
    importTemplate(command) {
      if (command == "stock") {
        window.location.href = './import.html';
      }
    },
    Daily() {
      const that = this;
      this.$confirm('此操作将生成今日执行单（已存在的不会更新）, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        this.loading = true;
        $.ajax({//更新今日执行单
          headers: requestHeaders(),
          url: `${BASE_URL2}/article/generateDailyInventory`,
          type: 'GET',
          complete: function (XMLHttpRequest) {
            that.loading = false;
            if (XMLHttpRequest.status == 200) {
              that.$message.success("今日库存单更新成功")
            } else {
              that.$message.error("今日库存单更新失败")
            }
          }
        })
      }).catch(() => { });
    },
    Show(Supplier_Article_Stock_SerialNumber) {
      this.Supplier_Article_Stock_SerialNumber = Supplier_Article_Stock_SerialNumber
      this.dialogVisible = true
    },
    Remove(row) {
      const that = this;
      this.$confirm('警告！此操作将删除该库存单, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning',
      }).then(() => {
        row.Row_Status = '1';
        $.ajax({
          headers: requestHeaders(),
          url: `${BASE_URL2}/generalBusiness/generalSave`,
          type: 'POST',
          data: {
            Data: JSON.stringify({ Modify: { business_supplier_article_stock: [row] } })
          },
          success: function (res) {
            if (res.Status === 'success') {
              that.$message({
                type: 'success',
                message: '删除成功!'
              });
              that.getList(that.form);
            } else {
              that.$message.error("删除失败，请稍后再试")
            }
          },
          complete: function (XMLHttpRequest) {
            that.loading = false
            requestPretreatment(XMLHttpRequest);
          },
          dataType: "json"
        })
      }).catch(() => { });
    }

  },
})